package com.nuanshui.heatedloan.web.ueditor;

import com.alibaba.fastjson.JSON;
import com.nuanshui.framework.res.ResourceFacade;
import com.nuanshui.framework.res.UploadRequest;
import com.nuanshui.framework.res.qiniu.UpLoadFileVO;
import com.nuanshui.heatedloan.enums.FileBelong;
import com.nuanshui.heatedloan.web.ApiController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

/**
 * @Author: Gonzo
 * @Date 2017/5/18下午8:18
 * @since 1.4.2
 */
@RestController
@RequestMapping("/static/plugin/vendor/ueditor/")
public class UEditorController extends ApiController{

    @Autowired
    private ResourceFacade resourceFacade;

    public static final String UPLOADIMAGE = "uploadimage";

    @RequestMapping("editor/controller")
    public String uEditorHandle(String id, String name, String type, String lastModifiedDate, Integer size, String action, @RequestParam("upfile") CommonsMultipartFile upfile){
        if (UPLOADIMAGE.equals(action) && upfile != null){
            try {
                UploadRequest request=new UploadRequest();
                request.setMultipartFile(upfile);
                UpLoadFileVO upLoadFileVO = resourceFacade.uploadFile(request).getFile();
                return  JSON.toJSONString(upLoadFileVO);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        return success();
    }



}
